﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace EmailSendFromGoogle
{
    public class Email
    {
        public void Send()
        {
            try
            {
                MailMessage mail = new MailMessage();
                mail.To.Add("edlabbe@gmail.com");
                mail.From = new MailAddress("sylvain.brodier@gmail.com");
                mail.Subject = "TEst Email using Gmail";

                string Body = "Hi, this mail is to test sending mail" +
                              "using Gmail in ASP.NET";
                mail.Body = Body;

                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
                smtp.Credentials = new System.Net.NetworkCredential
                     ("sylvain.brodier@gmail.com", "UnpfjEdN09,");
                //Or your Smtp Email ID and Password
                smtp.EnableSsl = true;
                smtp.Send(mail);
            }
            catch (Exception e)
            {
                
                throw;
            }
        }

        public void Send1()
        {
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential("sylvain.brodier@gmail.com", "UnpfjEdN09,"),
                EnableSsl = true, 
            };
            client.Send("sylvain.brodier@gmail.com", "edlabbe@gmail.com", "test", "testbody");
        }

        public void RealSend(string email, string prenom, string attachment)
        {
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential("sylvain.brodier@gmail.com", "UnpfjEdN09,"),
                EnableSsl = true,
            };

            var html = "bonjour " + prenom;

            var mail = new MailMessage();
            mail.From = new MailAddress("sylvain.brodier@gmail.com");
            //mail.To.Add(email);

            
            //todo enlever ca.
            mail.To.Add("edlabbe@gmail.com");

            //mail.To.Add("le NOmd e la prod")
            mail.Body = html;
            mail.Attachments.Add(new Attachment(attachment) );
            client.Send(mail);
            //client.Send("sylvain.brodier@gmail.com", email, "Tp1, partie 1", html);
            

        }
    }
}
